import axios from 'axios';
import Vue from 'vue';
import router from '../router/index'
const http = axios.create({
    baseURL: 'http://localhost:3000/admin/api',
})
http.interceptors.response.use(req => {
    return req
}, err => {
    Vue.prototype.$message.error(err.response.data.message)
    if (err.response.status == 401) {
        router.push('/login')
    }
    return Promise.reject(err.response)
})
http.interceptors.request.use((config) => {
    // Do something before request is sent
    if (localStorage.token)
        config.headers.Authorization = "Bearer " + localStorage.token
    return config;
}, function(error) {
    // Do something with request error
    return Promise.reject(error);
})
export default http